// ==UserScript==
// @name           Show as HTML Temporarily
// @namespace      http://www.quchao.com/entry/show-as-html-temporarily
// @description    Place a Show-as-HTML-Temporarily button on the expanded header panel.
// @include        main
// @compatibility  Thunderbird 3.0.*
// @author         Alexander Ihrig
// @author         Qu Chao (Chappell.Wat) <Chappell.Wat@Gmail.com>
// @version        1.1
// @Note
// ==/UserScript==
// ver 1.0 @ 2009-3-22
//  Initialize release
// ver 1.1 @ 2009-7-16
//  To be compatible for 3.6a1pre

(function() {
	window.showHtmlTemporarily = function () {
		// shortcuts
		let prefBranch = gPrefBranch;

		// cache default related settings
		var relatedSettings = [
			prefBranch.getBoolPref('mailnews.display.prefer_plaintext'),
			prefBranch.getIntPref('mailnews.display.html_as'),
			prefBranch.getIntPref('mailnews.display.disallow_mime_handlers')
		];

		// change related settings temporarily
		prefBranch.setBoolPref('mailnews.display.prefer_plaintext', false);
		prefBranch.setIntPref('mailnews.display.html_as', 0);
		prefBranch.setIntPref('mailnews.display.disallow_mime_handlers', 0);

		// show html now
		//LoadMsgWithRemoteContent();
		ReloadMessage();

		// restore focus
		RestoreFocusAfterHdrButton

		setTimeout(function () {
			prefBranch.setBoolPref('mailnews.display.prefer_plaintext', relatedSettings[0]);
			prefBranch.setIntPref('mailnews.display.html_as', relatedSettings[1]);
			prefBranch.setIntPref('mailnews.display.disallow_mime_handlers', relatedSettings[2]);
		}, 1000);
	}

	// place a button
	let buttonAnc = document.getElementById('expandedButtonBox').getButton('hdrReplyButton');
	const showHtmlButton = document.createElement('button');
	showHtmlButton.setAttribute('anonid', 'hdrHTMLButton');
	showHtmlButton.setAttribute('label', 'HTML');
	showHtmlButton.setAttribute('class', 'msgHeaderView-button');
	showHtmlButton.setAttribute('oncommand', 'showHtmlTemporarily();');
	showHtmlButton.setAttribute('hidden', 'false');
	buttonAnc.parentNode.insertBefore(showHtmlButton, buttonAnc);
})();